function request(method, url, data) {
  return new Promise(function (resolve, reject) {
    let header = {
      'content-type': 'application/json',      
      'AccessToken': wx.getStorageSync('accessToken')
    };
    wx.request({
      url: url,
      method: method,
      data: method === 'POST' ? JSON.stringify(data) : data,
      header: header,
      success(res) {
        if (res.statusCode === 200) {
          //请求成功
          if (res.data.code === 1) {
            resolve(res.data.data);
          } else {
            //其他异常
            reject(res.data.message);
          }
        } else {//返回错误提示信息
          reject(res.data);
        }
      },
      fail(err) {
        //请求失败
        //console.log('err',err)
        reject('服务器连接异常')
      }
    })
  })
}
 
const get = (url, data)=>{
  return request('GET',url,data)
}

const post = (url, data)=>{
  return request('POST',url,data)
}

module.exports = {
  get,
  post
}